package com.ape.mapsa.produccion.dao;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.sql.JoinType;
import org.springframework.stereotype.Repository;

import com.ape.mapsa.produccion.model.Confeccion;
import com.ape.mapsa.produccion.model.Extrusion;
import com.ape.mapsa.produccion.model.Impresion;

@Repository(value = "extrusionDAO")
public class AssignmentDAOImpl extends GenericDAOImpl<Extrusion, Long> implements AssignmentDAO {

	@Override
	public List<Extrusion> getAssginmentsByType(Integer type) {
		@SuppressWarnings("unchecked")
		List<Extrusion> maqAssigns = sessionFactory.getCurrentSession().createCriteria(Extrusion.class)
				.createAlias("maquina", "maq", JoinType.LEFT_OUTER_JOIN, Restrictions.like("maq.maqTipo", type)).addOrder(Order.asc("fechaInicio"))
				.list();
		return maqAssigns;
	}

	@Override
	public List<Extrusion> getByMaquinaId(Long id) {
		@SuppressWarnings("unchecked")
		List<Extrusion> maqAssigns = sessionFactory.getCurrentSession().createCriteria(Extrusion.class).add(Restrictions.gt("fechaFin", new Date()))
				.add(Restrictions.like("maquina.id", id)).addOrder(Order.asc("fechaInicio")).list();
		return maqAssigns;
	}

	@Override
	public List<Impresion> getImpAssginments(Integer impresionTypeId) {
		@SuppressWarnings("unchecked")
		List<Impresion> maqAssigns = sessionFactory.getCurrentSession().createCriteria(Impresion.class).add(Restrictions.gt("fechaFin", new Date()))
				.createAlias("maquina", "maq", JoinType.LEFT_OUTER_JOIN, Restrictions.like("maq.maqTipo", impresionTypeId))
				.addOrder(Order.asc("fechaInicio")).list();
		return maqAssigns;
	}

	@Override
	public List<Confeccion> getConfAssginments(Integer impresionTypeId) {
		@SuppressWarnings("unchecked")
		List<Confeccion> maqAssigns = sessionFactory.getCurrentSession().createCriteria(Confeccion.class)
				.add(Restrictions.gt("fechaFin", new Date()))
				.createAlias("maquina", "maq", JoinType.LEFT_OUTER_JOIN, Restrictions.like("maq.maqTipo", impresionTypeId))
				.addOrder(Order.asc("fechaInicio")).list();
		return maqAssigns;
	}

}
